package com.example.administrator.yunniuusedcar.fragment.ShoppInfo_Fragment;


import android.annotation.SuppressLint;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.example.administrator.common.base.BaseFragment;
import com.example.administrator.common.base.Global;
import com.example.administrator.yunniuusedcar.R;
import com.example.administrator.yunniuusedcar.adapter.ShopInfon_TWAdapter;
import com.example.administrator.yunniuusedcar.model.mode_benn.IHttpService;
import com.example.administrator.yunniuusedcar.model.mode_benn.RanCarXiangQingBean;
import com.google.gson.Gson;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.ArrayList;

import okhttp3.Call;

/**
 * Created by Administrator on 2017/12/8.
 * 商品详情 - 图文信息
 */

@SuppressLint("ValidFragment")
public class TuWenInfoFragment extends BaseFragment {
    private android.support.v7.widget.RecyclerView recyclerView;
    private int resultID;

    @SuppressLint("ValidFragment")
    public TuWenInfoFragment(int car_id) {
        super();
        resultID = car_id;
    }

    @Override
    public int getLayoutRes() {
        return R.layout.item_recycleview_3;
    }

    @Override
    public void initView() {
        initFindViewId();
        loadDatas();
        Intent intent = getActivity().getIntent();



        recyclerView = (RecyclerView) findView(R.id.recycler_view6);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    }

    private void initFindViewId() {
    }

    @Override
    public void initListener() {

    }

    @Override
    public void initData() {

    }

    private void loadDatas() {
        String ul = IHttpService.HOST_URL + "Car/getcarInfo";    // 图文 详情
        //String.valueOf(resultID)  car_id
        OkHttpUtils.post().url(ul).addParams("sign",IHttpService.SignVal).addParams("car_id", String.valueOf(resultID)).build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Global.showToast("RanCarInfo ERRor" + e);
                    }

                    @Override
                    public void onResponse(String response, int id) {
                        //
                        RanCarXiangQingBean ranCarInfoBean = new Gson().fromJson(response, RanCarXiangQingBean.class);
                        if(ranCarInfoBean.code==1){

                            ShopInfon_TWAdapter shopInfonJbAdapter = new ShopInfon_TWAdapter(getContext());
                            recyclerView.setAdapter(shopInfonJbAdapter);

                            shopInfonJbAdapter.refreshData(ranCarInfoBean.data.list.detail);
                        }

                    }
                });
    }
}
